<?php
namespace Disk\Controller;

use Think\Controller;
//use Think\Upload;
/**
 * @author 水月居 <87807564@qq.com>
 * @copyright 水月居
 * 
 */
 
class UploadifyController extends Controller{
	public function index(){
		if(session('loginname')){//判断用户是否登录
			$uer_name = session('loginname');	
			$this->assign('name',$uer_name);//输出主页面当前登录用户
			$this->display();
		}
		else
			redirect(U('Login/index'));
	}
	
	public function upload(){
		$uer_name = session('loginname');//获取登录用户名

		$return = array('status' => 1, 'info' => '上传成功！', 'data' => '');
        /* 调用文件上传组件上传文件 */
        $filesModel= D('Disk/DiskFiles');
        $driver = modC('DOWNLOAD_UPLOAD_DRIVER','local','config');
        $driver = check_driver_is_exist($driver);
        $uploadConfig = get_upload_config($driver);
        $setting = C('DISK_UPLOAD');
        $setting['maxSize'] = '1073741824'; // 设置附件上传大小1G
        $setting['savePath'] = $uer_name.'/'; // 设置附件上传目录
        $setting['replace'] = true;
        $setting['exts'] ="";
          // dump($setting);
        // dump($driver);
        // dump($filesModel);die;
        $files=$_FILES;
        // dump($files);

        $info = $filesModel->upload(
            $files,
            $setting,           
            $driver
            );
        // dump($info);

        /* 记录附件信息 */
        if ($info) {
            $return['data'] = $info;
        } else {
            $return['status'] = 0;
            $return['info'] =$filesModel->getError();
        }
        // dump($return);die;

        /* 返回JSON数据 */
        $this->ajaxReturn($return);

	}
	
	public function del(){
			$file_name=$this->_get('file_name');//get方法获取前台数据
			$arr = split(",",$file_name);
			$uer_name = session('loginname');
			//$file_path=$this->_get('file_path');
			for($i=0;$i<count($arr);$i++){
				$file_path=trim("/Public/Upload/".$uer_name.'/'.$arr[$i]);
				unlink($_SERVER['DOCUMENT_ROOT'].$file_path);//删除文件
		    	$file = M("Files"); // 实例化file对象
    			$file->where("file_name='$arr[$i]'")->delete(); // 删除file_name为用户当前点击文件的文件名
			}
}
}